<?php

class VisitlogModel extends DBModel
{
	protected $_table = '{{visitlog}}';
	protected $_id = 'id';
	
	public function getList($userid, $limit = 50)
	{
		$sql = 'select * from 
					(select u.userid,u.nickname truename,v.createtime visitime,p.midpath from {{visitlog}} v 
						left join {{user}} u on u.userid = v.visituserid left join {{photo}} p on p.photoid = u.logoid 
						where v.indexuserid = :indexuserid 
						order by v.createtime desc limit '. $limit .'
					) t group by userid order by visitime desc';
// 		$where['from'] = '{{visitlog}} v';
// 		$where['select'] = 'u.userid,u.nickname truename,v.createtime visitime,p.midpath';
// 		$where['join'] = 'left join {{user}} u on u.userid = v.visituserid left join {{photo}} p on p.photoid = u.logoid';
// 		$where['condition'] = 'v.indexuserid = :indexuserid';
// 		$where['order'] = 'v.createtime DESC';
// 		$where['group'] = 'u.userid';
// 		$where['limit'] = $limit;
		$params[':indexuserid'] = $userid;
// 		return $this->findAll($where, $params);
		return $this->queryBySql($sql, $params, 'queryAll');
	}
}